<?php


namespace app\cms\model;


use app\cms\community\lib\QueryModel;
use app\community\UserAgent;

class loginLogsModel extends QueryModel
{
    protected $table = "login_logs";

    /**
     * 创建登录记录
     * @param int $uid 用户id
     * @param string $user_name 用户名
     * @param string $message 登录信息
     * @return array
     */
    public function createLogsInfo(int $uid, string $user_name, string $message): array {
        $userAgent = (new UserAgent()) -> Get_User_Surroundings();
        return self::create([
            'uid' => $uid,
            'user_name' => $user_name,
            'ip_address' => $userAgent['ip'],
            'address' => $userAgent['ip_address'],
            'os' => $userAgent['os'],
            'chrome' => $userAgent['chrome'],
            'message' => $message
        ]) -> toArray();
    }
}